// miniprogram/pages/hb-res/hb-res.js
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    var res = wx.getStorageSync('jjres')
    var phone = wx.getStorageSync('phone')
    if (res) {
      that.setData({
        res: res + '元'
      })
      wx.request({ //发送请求
        url: 'https://zg99.offcn.com/index/choujiang/updateuser?actid=39413&callback=?', //接收url
        data: {
          phone: phone,
          res: res
        }, //接收参数
        success(res) {
          var jsonStr = res.data;
          jsonStr = jsonStr.replace("(", "");
          jsonStr = jsonStr.replace(")", "");
          if (typeof jsonStr != 'object') {
            jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
            var theJson = JSON.parse(jsonStr);
          }
          console.log(theJson)
        }
      })
    } else if (phone) {
      wx.request({ //发送请求
        url: 'https://zg99.offcn.com/index/choujiang/getphonestatus?actid=39413&callback=?', //接收url
        data: {
          phone: phone
        }, //接收参数
        success(res) {
          var jsonStr = res.data;
          jsonStr = jsonStr.replace("(", "");
          jsonStr = jsonStr.replace(")", "");
          if (typeof jsonStr != 'object') {
            jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
            var theJson = JSON.parse(jsonStr);
          }
          console.log(theJson.status)
          if (theJson.status == 1) {
            console.log(theJson.user.res)
            that.setData({
              res: theJson.user.res + '元'
            })
          } else {
            wx.redirectTo({
              url: '../hb-index/hb-index',
            })
          }
        }
      })
    } else {
      // wx.redirectTo({
      //   url: '../hb-index/hb-index',
      // })
    }


  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },
  /**右上角分享*/
  onShareAppMessage: function () {
    var that = this;
    console.log(that.data.p_open_id)
    return {
      title: '山东中公进面红包领取’',
      path: 'pages/hb-index/hb-index?area=' + that.data.area + '&agent=' + that.data.geneal + '&page=' + that.data.page
    }
  },
  /**分享到朋友圈*/
  onShareTimeline: function () {
    var that = this;
    console.log(that.data.p_open_id)
    return {
      title: '山东中公进面红包领取’',
      path: 'pages/hb-index/hb-index?area=' + that.data.area + '&agent=' + that.data.geneal + '&page=' + that.data.page
    }

  }


})